package com.nb82.bean.weather;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;


public class HTTPUtil {
	// http://open.weather.com.cn/data/?
	// areaid=101010100&
	// type=observe&date=201212031008&
	// appid=cf2d61&
	// key=w%2B1%2BfvngN50nJJh6xdu6Mfu7jxg%3D


	private static HTTPUtil util;

	/**
	 * this method is HttpPost
	 * 
	 * @param httpUrl
	 * @return if post OK, return String with this post . else return null.
	 */
	public String httpGet(String httpUrl) {
		// TODO Auto-generated method stub
		synchronized (HTTPUtil.class) {
			HttpGet httpRequest = new HttpGet(httpUrl);
			try {
				/* ������������������� */
				// Log.w(this.getClass().getSimpleName(), " post ........");
				DefaultHttpClient client = new DefaultHttpClient();

				HttpResponse httpResponse = client.execute(httpRequest);

				/* ��״̬��Ϊ200 ok */
				// System.out.println(httpResponse.getStatusLine().getStatusCode());
				if (httpResponse.getStatusLine().getStatusCode() == 200) {
					/* ���������� */
					// System.out.println("11");
					String strResult = EntityUtils.toString(httpResponse
							.getEntity(),"utf-8");
					return strResult;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	public static HTTPUtil getInstance() {
		return util != null ? util : new HTTPUtil();
	}
	private HTTPUtil() {
	}
}
